# Maintainer: Martell Malone <martellmalone@gmail.com>

_realname=qemu
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
_base_ver=4.1.0
_rc=
pkgver=${_base_ver}${_rc//-/.}
pkgrel=1
pkgdesc="A generic and open source processor emulator (mingw-w64)"
arch=('any')
license=('GPL2' 'LGPL2')
url="https://qemu.org/"
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-python3"
             'perl' 'bison' 'bsdtar')
depends=("${MINGW_PACKAGE_PREFIX}-capstone"
         "${MINGW_PACKAGE_PREFIX}-curl"
         "${MINGW_PACKAGE_PREFIX}-cyrus-sasl"
         "${MINGW_PACKAGE_PREFIX}-glib2"
         "${MINGW_PACKAGE_PREFIX}-gnutls"
         "${MINGW_PACKAGE_PREFIX}-gtk3"
         "${MINGW_PACKAGE_PREFIX}-libjpeg"
         "${MINGW_PACKAGE_PREFIX}-libpng"
         "${MINGW_PACKAGE_PREFIX}-libssh"
         "${MINGW_PACKAGE_PREFIX}-libtasn1"
         "${MINGW_PACKAGE_PREFIX}-libusb"
         "${MINGW_PACKAGE_PREFIX}-libxml2"
         "${MINGW_PACKAGE_PREFIX}-lzo2"
         "${MINGW_PACKAGE_PREFIX}-nettle"
         "${MINGW_PACKAGE_PREFIX}-pixman"
         "${MINGW_PACKAGE_PREFIX}-snappy"
         "${MINGW_PACKAGE_PREFIX}-SDL2"
         "${MINGW_PACKAGE_PREFIX}-SDL2_image"
         "${MINGW_PACKAGE_PREFIX}-usbredir")
source=(https://download.qemu.org/${_realname}-${pkgver}.tar.xz
        001-iovec-sasl-conflict.patch)
sha256sums=('656e60218689bdeec69903087fd7582d5d3e72238d02f4481d8dc6d79fd909c6'
            '87525c95012de861fc7d5ff1554741ed23fae732bb50258a9d8083c43c5a2420')
noextract=(${_realname}-${pkgver}.tar.xz)

prepare() {
    [[ -d "${srcdir}"/${_realname}-${pkgver} ]] && rm -rf "${srcdir}"/${_realname}-${pkgver}
    tar -xJf ${srcdir}/${_realname}-${pkgver}.tar.xz -C ${srcdir} || true

    cd "${srcdir}/${_realname}-${pkgver}"
    patch -p1 -i ${srcdir}/001-iovec-sasl-conflict.patch
}

build() {
    cd "${srcdir}/${_realname}-${pkgver}"
    ./configure \
        --disable-stack-protector \
        --disable-werror \
        --disable-kvm \
        --disable-bluez \
        --disable-spice \
        --disable-libnfs \
        --enable-libssh \
        --enable-lzo \
        --enable-snappy \
        --enable-hax \
        --enable-gtk \
        --enable-sdl \
        --prefix=${MINGW_PREFIX} \
        --bindir=${MINGW_PREFIX}/bin \
        --datadir=${MINGW_PREFIX}/bin \
        --firmwarepath=${MINGW_PREFIX}/etc/qemu \
        --python=${MINGW_PREFIX}/bin/python3 \
        --mandir=${MINGW_PREFIX}/share/qemu \
        --docdir=${MINGW_PREFIX}/share/qemu
    make -j1
}

package() {
    cd "${srcdir}/${_realname}-${pkgver}"
    make DESTDIR="${pkgdir}/" install
}
